{extend name="public:base" /}
{block name="head"}
<link href="__PUBLIC__/view_res/mobile/css/wshop_company_center.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/view_res/mobile/css/login.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/css/jquery-weui.min.css" type="text/css" rel="Stylesheet" />
<script src="__PUBLIC__/jquery-weui/dist/js/jquery-weui.min.js"></script>
<link href="__PUBLIC__/view_res/mobile/css/uc.css" type="text/css" rel="Stylesheet" />

{/block} 
{block name="header"}
{include file="public/top-nav" /}
{/block}

{block name="content"}
    <style>
        body{
            background:none;
        }
    </style>
    <header class="Thead">交易品兑换</header>

    {:token()}

    <div style="margin:0 10px;">
        <div class="gs-text">
            <select name="exchange_id" style="width: 100%; height: 28px"  id ="exchange_id">
                <option value ="">--   交易所   --</option>
                {volist name="exchange" id="ex"}
                <option value="{$ex.id}" {if condition="input('param.exchange_id') eq $ex.id"} selected {/if} >{$ex.name}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div style="margin:0 10px;">
        <div class="gs-text">
            <select name="variety_id" style="width: 100%; height: 28px"  id="variety_id">
                <option value="">--   交易品种   --</option>
            </select>
        </div>
    </div>
    <div style="margin:0 10px;">
        <div class="gs-text">
            <input type="number" name="num" value=""  tabindex="2" placeholder="请输入兑换的枚数" autocomplete="off"/>
        </div>
    </div>
    <div style="margin:0 10px;">
        <div class="gs-text">
            <input type="password" name="pwd2" value=""  tabindex="2" placeholder="请输入二级密码" autocomplete="off"/>
        </div>
    </div>
    <div style="margin:0 10px;">
        <span id="sho">收盘价</span>&nbsp;-&nbsp;<span id="ren">认购价</span>&nbsp;=&nbsp;<span id="jie">元宝&nbsp;/&nbsp;枚</span>
        <br>
        <span id="max"></span>
    </div>
    <input class="button btn-danger" id="reg-btn" type="submit" value="确认提交" style="background: #e54245;">

    <header class="Thead">交易品兑换记录</header>
<!-- 
    <form style="position:relative;border-bottom: 1px dashed #dedede;" action="{:url('contract/change')}" id="login-wrap" method="get">

        <input class="sous" type="submit" value="搜索" style="position: absolute; bottom:15%;right: 25%;width: 45px;text-align: center;height: 25px;    border-radius: 5px;color: #fff;box-shadow: 1px 1px 2px #907777; background: #b95f5f;">
    </form> -->
    <div id="ulist">
        {volist name="list" id="p"}
        <section class="ulist clearfix">
            <div>
                <span class="ulist_p">{:date('Y-m-d',$p.create_time)}</span>
                <span class="ulist_data" style="padding:0 8px;display: block;">

                    交易所：{:get_trade_name($p.exchange_id)}<br>
                    交易品种：{:get_variety_name($p.variety_id)}<br>
                    使用元宝：{$p.money}<br>
                    兑换票数：{$p.num}<br>
                    交易所需持仓：{:get_contract_issue($p.variety_id)*$p.num+$p.num*0.3}<br>
                    {if condition="$p.state eq 0"}
                    状态：审核中
                    {elseif condition="$p.state eq 1"}
                    状态：审核通过
                    {elseif condition="$p.state eq 2"}
                    状态：审核不通过
                    {/if}
                </span>
            </div>
        </section>
        {/volist}
    </div>
    <div style="text-align: right;padding:2% 3%;">
        数据总数:{$list->total()}条
        {$page}
    </div>
    <script type="text/javascript">
        $('#exchange_id').change(function(){
            //alert("abc");
            var iframe_array = <?php echo  json_encode($variety);   ?>;
            var checkValue=jQuery("#exchange_id").val();
            //alert(checkValue);
            $("#variety_id").empty();
            for (var i = 0; i <iframe_array.length ; i++)
            {
                if(iframe_array[i]['exchange_id']==checkValue)
                {
                    var opt = "<option value='"+iframe_array[i]['id']+"'>"+iframe_array[i]['name']+"</option>";
                    jQuery("#variety_id").append(opt);
                }
            }

        })
    </script>
    <script>
        $('#reg-btn').click(function(){

            var exchange_id = $('#exchange_id option:selected').val();
            var variety_id  = $('#variety_id option:selected').val();
            var password    = $('input[type="password"]').val();
            var number      = $('input[type="number"]').val();
            var hidden      = $('input[type="hidden"]').val();
            $.ajax({
                url : '{:url("contract/change")}',
                data : {exchange_id:exchange_id,variety_id:variety_id,pwd2:password,number:number,token:hidden},
                type : 'post',
                success:function(d){
                    if(d.error){
                        $.toast(d.error, "forbidden");
                        if(d.url){
                            setTimeout(function (){
                                window.location.href = d.url;
                            },1000);
                        }
                    }else if(d.success){
                        $.toast(d.success);
                        setTimeout(function (){
                            window.location.href = "/mobile/contract/change";
                        },1000);
                    }
                }
            });

        });
    </script>
    <script>

        $('#variety_id').change(function(){
            var variety_id  = $('#variety_id option:selected').val();
            variety(variety_id);

        });

        $('#exchange_id').change(function(){
            var variety_id  = $('#variety_id option:selected').val();
            variety(variety_id);

        });

        function variety(variety_id){
            $.ajax({
                url : '{:url("contract/yesterday")}',
                data : {variety_id:variety_id},
                type : 'post',
                success:function(d){
                    if(d.code == 0){
                        $.toast(d.msg, "forbidden");
                    }else if(d.code == 1){

                        console.log(d)
                        /*var ren = 0;
                        //一号
                        if(variety_id == 5)
                        {
                            ren = 44;
                        }
                        //二号
                        else if(variety_id == 6)
                        {
                            ren = 50;
                        }
                        //三号
                        else if(variety_id == 7)
                        {
                            ren = 100;
                        }
                        var jie = d.data.rate-ren;
                         */
                        $('#sho').html(d.data.rate);
                        $('#ren').html(d.data.issue);
                        $('#jie').html(d.data.jie+'&nbsp;/&nbsp;枚');

                        $('#max').html('当前元宝余额为：'+d.data.jilin_bean+'，最大可兑换枚数为&nbsp;'+d.data.yu+'&nbsp;枚');

                    }
                }
            });
        }

    </script>
{/block}